
********************************************************************************
* Data creation
********************************************************************************

* MERGE INDIVIDUAL DATA WITH HOUSEHOLD IHDS DATA - FEMALES DATASET

* Data at the household level (it includes WOMEN'S QUESTIONNAIRE)
use "$ORIGINAL/22626-0002-Data.dta", clear
sort STATEID DISTID PSUID HHID HHSPLITID IDHH
tempfile hh_data
save "`hh_data'", replace

* Data at the individual level
use "$ORIGINAL/22626-0001-Data.dta", clear
sort STATEID DISTID PSUID HHID HHSPLITID IDHH PERSONID
tempfile ind_data
save "`ind_data'", replace

merge m:1 STATEID DISTID PSUID HHID HHSPLITID IDHH using "`hh_data'"

tempfile ind_hh
save "`ind_hh'", replace

rename RO0 id
rename RO3 sex
rename RO4 rel_hh 
rename RO5 agew
rename RO6 mar_status
rename RO7 id_spouse
rename ED5 educw

rename EW3 id_wq
rename EW4 rel_hh_wq
rename EW5 age_wq
rename EW7 educ_wq
rename EW8 nchild_wq

rename MH1AC marr_age_wq
rename MH2AC gauna_age_wq
rename MH9 dist
rename ID13 caste
rename ID3 state
rename ID14 religion
rename GR16 papers

rename MP3A wedboy_lb
rename MP3B wedboy_ub
rename MP4A wedgirl_lb
rename MP4B wedgirl_ub

rename INCOME income
rename INCOME5 income5

gen yy_1marr = 2005 - (age_w - marr_age_wq) 


********************************************************************************
* Sample selection
********************************************************************************

keep if rel_hh == 2 & sex == 2
keep if agew>=15 & agew<=49
keep if mar_status == 1
drop if MH1A <0 | MH1A >40
keep if yy_1marr>=1975 & yy_1marr<=1999
drop if MH17A == 2

********************************************************************************
* Treatment

gen dowr_year = 1986
gen dow_cohort = (dowr_year <= yy_1marr) 
replace dow_cohort = . if yy_1marr == . | dowr_year == . 

gen hindu = (religion == 1 )
gen christian = (religion == 3)
gen muslim = (religion == 2)

replace hindu = . if religion == .
gen hindu1 = (religion!=2)

gen dowTreat = dow_cohort * hindu1

label var dow_cohort "Post"
label var hindu1 "Non-Muslim"


gen yearb = 2005 - agew
replace educw = . if educw<0
replace dist = . if dist<0
gen ldist = log(1+dist)
drop if age_wq <15

gen work = WKSALARY
gen n_kids = NCHILDREN
gen hhsize = NPERSONS
gen rural = (ID9 == 1)

gen  scstbc = (caste == 2|caste == 3| caste==4)

* Norms about wife beating

gen beat_nodowry = (GR22 == 1)
replace beat_nodowry = . if GR22<0

gen beat_badcook = (GR24 == 1)
replace beat_badcook = . if GR24<0

gen beat_extramarital = (GR25 == 1)
replace beat_extramarital = . if GR25<0

gen beat_goesalone = (GR21 == 1)
replace beat_goesalone = . if GR21<0

gen beat_just = (beat_nodowry == 1 | beat_badcook == 1 | beat_extramarital == 1 | beat_goesalone == 1)
replace beat_just = . if (beat_nodowry == . | beat_badcook == . | beat_extramarital == . | beat_goesalone == .)


* Marital sorting and matching

* Generate dummy for arranged marriage
gen arranged_marr = (MH5A==3)
replace arranged_marr  = . if  MH5A<0

* Generate dummy for same caste (1: same; 0: different)
gen samecaste = .
replace samecaste = 1 if MH7==1 
replace samecaste = 0 if MH7==0 

* Generate dummy for marry-up (1: up; 0: same or lower)
gen marryup = .
replace marryup = 1 if MH13==2
replace marryup = 0 if MH13==1 | MH13==3

* Generate dummy for other woman married in husband's family
gen othwoman_infam = . 
replace othwoman_infam = 1 if MH11 > 0 & MH11 != .
replace othwoman_infam = 0 if MH11 == 0

* Generate dummy for other woman married in same village
gen othwoman_invill = . 
replace othwoman_invill = 1 if MH12 > 0 & MH12 != .
replace othwoman_invill = 0 if MH12 == 0

* Generate dummy for husband blood related
gen hus_bloodrel = . 
replace hus_bloodrel = 1 if MH10 == 1 | MH10 == 2 | MH10 == 3
replace hus_bloodrel = 0 if MH10 == 0

* Generate dummy for living alone with husband after marriage
gen liveaftermarriage = .
replace liveaftermarriage = 1 if MH8 == 1
replace liveaftermarriage = 2 if MH8 == 2
replace liveaftermarriage = 3 if MH8 == 3

gen livealoneaftermarr = (liveaftermarriage == 3)
replace livealoneaftermarr = . if liveaftermarriage == .

* Generate dummy for living with husband's familyafter marriage
gen livewinlaws = (liveaftermarriage == 1)
replace livewinlaws = . if liveaftermarriage == .

* Generate dummy for meeting husband's on wedding day or less than one month before
gen methusband_atwed = (MH4 == 1 |MH4 == 2)
replace  methusband_atwed = . if MH4 < 1


* Generate wealth index
gen tv= (CG7 == 1 | CG8 == 1)
gen ref = (CG16 == 1)
gen bike = (CG2 == 1)
gen house = (CG1 ==1)
gen mbike = (CG6 == 1)
gen car = (CG18 == 1)

pca ref tv bike mbike car house, comp(1) 

estat kmo 
predict f1 
rename f1 fpc_wealth 
sum fpc_wealth 
replace fpc_wealth = (fpc_wealth - r(min))/(r(max)-r(min)) 


gen ihdssample = 1 // this is for marriage market effects 

save "$OUTDATA/IHDS_sample.dta", replace 
